<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.5.5/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <div>
            <input type="hidden" name="id" lay-verify="required"
                   class="layui-input" th:value="${model.id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required"
                   lay-reqtext="宿舍名不能为空" placeholder="请输入宿舍名" value="" class="layui-input"
                   th:value="${model.name}">
            <tip>填写宿舍名字</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">剩余电量</label>
        <div class="layui-input-block">
            <input type="number" name="surplusPower" lay-verify="required"
                   lay-reqtext="初始电量不能为空" placeholder="请输入初始电量" value="100" class="layui-input"
                   th:value="${model.surplusPower}" disabled>
            <tip>剩余电量不允许修改</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">几人寝</label>
        <div class="layui-input-block">
            <select name="severalPeople" lay-verify="required">
                <option value="4" th:selected="${model.severalPeople} eq 4">4人寝</option>
                <option value="5" th:selected="${model.severalPeople} eq 5">5人寝</option>
                <option value="6" th:selected="${model.severalPeople} eq 6">6人寝</option>
                <option value="7" th:selected="${model.severalPeople} eq 7">7人寝</option>
                <option value="8" th:selected="${model.severalPeople} eq 8">8人寝</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script th:src="@{/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
<script lang="JavaScript", th:inline="javascript">
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            console.log(JSON.stringify(data.field));

            $.ajax({
                url: "../../api-v1/domitory/edit",
                method: "post",
                data: JSON.stringify(data.field),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var index = layer.alert(result.msg, {
                        title: '提交信息',
                        icon: 1
                    }, function () {
                        // 关闭弹出层
                        layer.close(index);

                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        // 重载表格
                        window.parent.location.reload();
                    });
                }
            });
            return false;
        });
    });
</script>
</body>
</html>